using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

using AudioDjStudio;

namespace IntelliTouchMix
{
	public partial class FormFaderSetup : Form
	{
		public FormFaderSetup()
		{
			InitializeComponent();
		}

		public FormMain frmMain;

		private void ValidateValues()
		{
			if (CheckFadeOutEnabled.Checked)
				frmMain.audioDjStudio1.Fader.FadeOutEnabled = true;
			else
				frmMain.audioDjStudio1.Fader.FadeOutEnabled = false;

			if (CheckFadeInEnabled.Checked)
				frmMain.audioDjStudio1.Fader.FadeInEnabled = true;
			else
				frmMain.audioDjStudio1.Fader.FadeInEnabled = false;
		    
			frmMain.audioDjStudio1.Fader.FadeStartFromEnd = Convert.ToInt32 (TextFadeStartFromEnd.Text);
			frmMain.audioDjStudio1.Fader.FadeOutLength = Convert.ToInt32 (TextFadeOutLength.Text);
			frmMain.audioDjStudio1.Fader.FadeInLength = Convert.ToInt32 (TextFadeInLength.Text);
			frmMain.audioDjStudio1.Fader.FadeInSeekPos = Convert.ToInt32 (TextFadeInSeekPos.Text);
			frmMain.audioDjStudio1.Fader.FadeOutDelayFromMixStart = Convert.ToInt32 (TextFadeOutDelay.Text);
			frmMain.audioDjStudio1.Fader.FadeInDelayFromMixStart = Convert.ToInt32 (TextFadeInDelay.Text);
			frmMain.audioDjStudio1.Fader.FadeOutMode = (enumFadeOutModes) ComboFadeOutType.SelectedIndex;

			LabelTotalTime.Text = frmMain.audioDjStudio1.Fader.TotalMixingTime.ToString() + " ms";
		}

		private void FormFaderSetup_Load(object sender, EventArgs e)
		{
			if (frmMain.audioDjStudio1.Fader.FadeOutEnabled)
				CheckFadeOutEnabled.Checked = true;

			if (frmMain.audioDjStudio1.Fader.FadeInEnabled)
				CheckFadeInEnabled.Checked = true;

			TextFadeStartFromEnd.Text = frmMain.audioDjStudio1.Fader.FadeStartFromEnd.ToString ();
			TextFadeOutLength.Text = frmMain.audioDjStudio1.Fader.FadeOutLength.ToString();
			TextFadeInLength.Text = frmMain.audioDjStudio1.Fader.FadeInLength.ToString();
			TextFadeInSeekPos.Text = frmMain.audioDjStudio1.Fader.FadeInSeekPos.ToString();
			TextFadeOutDelay.Text = frmMain.audioDjStudio1.Fader.FadeOutDelayFromMixStart.ToString();
			TextFadeInDelay.Text = frmMain.audioDjStudio1.Fader.FadeInDelayFromMixStart.ToString();
			ComboFadeOutType.Items.Add ("Volume based");
			ComboFadeOutType.Items.Add ("Breakdown");
			ComboFadeOutType.SelectedIndex = (int) frmMain.audioDjStudio1.Fader.FadeOutMode;
		    
			frmMain.audioDjStudio1.Fader.Display.Create (ctl3dFaderDisplay.Handle);

			Timer1.Enabled = true;
		}

		private void BtnOK_Click(object sender, EventArgs e)
		{
			ValidateValues ();
			frmMain.audioDjStudio1.Fader.Display.Show(false);
			Close();
		}

		private void BtnCancel_Click(object sender, EventArgs e)
		{
			frmMain.audioDjStudio1.Fader.Display.Show(false);
			Close();
		}

		private void Timer1_Tick(object sender, EventArgs e)
		{
			Timer1.Enabled = false;
			frmMain.audioDjStudio1.Fader.Display.Show (true);
			LabelTotalTime.Text = frmMain.audioDjStudio1.Fader.TotalMixingTime.ToString() + " ms";
		}

		private void BtnApply_Click(object sender, EventArgs e)
		{
			ValidateValues();
			frmMain.audioDjStudio1.Fader.Display.Show(true);
		}
	}
}